package com.jxsm.cz.util;

import com.jfinal.plugin.activerecord.Record;
import com.jxsm.jfinal.core.JxDb;
import net.sourceforge.pinyin4j.PinyinHelper;

import java.util.List;


/**
 * @author guodegen
 * @description
 * @date 2020/12/17 12:12
 */
public class PinyinUtil {

    public static void main(String[] args) {
        // 这里为什么用字符串数组接受返回的拼音呢，因为中文有多音字，输入“长”，会返回zhang3和chang2,（2,3表示第几声)
        String[] pinyin = PinyinHelper.toHanyuPinyinStringArray("单".charAt(0)); // str.charAt(0) 第一个汉字
        for (String py : pinyin) {
            System.out.println(py);
        }
    }

    public static void updateJc(List<Record> list){
        for(Record record:list){
            String firstChar = record.get("loc_name").toString().substring(0,1);
            String[] pinyin = PinyinHelper.toHanyuPinyinStringArray(firstChar.charAt(0));
            /*StringBuffer sb = new StringBuffer();
            for(String py:pinyin){
                sb.append(py.substring(0,1));
            }*/
            String sb = pinyin[0].substring(0,1).toUpperCase();
            JxDb.update("update system_loc set loc_jc=? where loc_id=?",sb.toString(),record.get("loc_id"));
        }
    }
}
